<!DOCTYPE html>
<html><head>
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" CONTENT="no-cache">
<meta content="telephone=no" name="format-detection" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
<title>开票</title>
<link type="text/css" rel="stylesheet" href="../../resource/fapiao.css">
<link rel="stylesheet" href="../../resource/weui.min.css"/>
<link rel="stylesheet" href="../../resource/example.css"/>
<!-- 微信引入 -->
<script type="text/javascript" src="../../resource/jweixin-1_002.js"></script>
<script type="text/javascript" src="../../resource/jweixin-1.js"></script>
<script src="../../resource/jquery-1.js"></script>
<script src="../../resource/qrcode.js"></script>
<script src="../../resource/jquery-barcode.js"></script>
<script src="../../script/api.js"></script>
<link rel="stylesheet" href="../../resource/jinsuistyle.css" />

<style>
	ul.list li{float:left;}
	a.btn2{
		line-height: 40px;
		display: block;
		color: #fff;
		padding-left:5%;
		background:#333;
		font-size:12px;
		border-bottom:1px solid #000;
	}
	a.btn2:hover {
		width: 100%;
		height: 100%;
		display: block;
		background: #000;
		cursor: pointer;
	}
	body{
	    overflow-x: hidden;
	}
	.FP_box{
		box-shadow:0 1px 0.2em #333;
	}
		.barcodeImg{margin:20px 0;}
	</style>
</head>

<body>
	<div id="jsheader">
			<nav id="jsnav">
					<a id="jsleft" tapmode="" onclick="api.closeWin();">
							<span>返回</span>
					</a>
					<div id="jsmiddle">
							<strong id="jstitle">极速开票</strong>
					</div>
					<a id="jsright">
						<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
					</a>
			</nav>
	</div>
	<div style="height:45px">&nbsp;</div>
   <div class="weui-search-bar" id="searchBar">

            <form class="weui-search-bar__form">
                <div class="weui-search-bar__box">
                    <i class="weui-icon-search"></i>
                    <input type="search" class="weui-search-bar__input" id="searchInput" placeholder="输入税号或名称搜索" required/>
                    <a href="javascript:" class="weui-icon-clear" id="searchClear"></a>
                </div>
                <label class="weui-search-bar__label" id="searchText">
                    <i class="weui-icon-search"></i>
                    <span>输入税号或名称搜索</span>
                </label>
            </form>
            <a href="javascript:" class="weui-search-bar__cancel-btn" id="searchCancel">取消</a>
        </div>
        <div class="weui-cells searchbar-result" id="searchResult" style="display:none;width:100%;position:absolute;top:70px;z-index:500;">
        <!-- 快速筛选列表 -->
        </div>
	<div id="loadingToast" style="display:none;">
        <div class="weui-mask_transparent"></div>
        <div class="weui-toast">
            <i class="weui-loading weui-icon_toast"></i>
            <p class="weui-toast__content">数据加载中...</p>
        </div>
	</div>
	<div class="page__hd" style="display:none;">
        <h1 class="page__title">
            极速开票
        </h1>
        <img src="../../resource/images/icon_nav_form.png" onclick="show()" alt="">
    </div>
	<div id="dialog" style="display: none;">
		<ul class="list absolute" style="width:50%; top:40px;right:0; z-index:100;position: absolute;">
			<li style="width:100%;"><a class="btn2" href="">aaa</a></li>
			<li style="width:100%;"><a class="btn2" href="">bbb</a></li>
			<li style="width:100%;"><a class="btn2" href="">ccc</a></li>
		</ul>
	</div>

	<div id="FP_boxs">

	</div>
	<div id="null_indicator" class="FP_btn">
		<a style="display:inline-block;display:-moz-inline-stack;width: 90%;color: #888;" href="javascript:;" onclick="addInfo()">
			<strong>+</strong>&nbsp;新增企业信息
		</a>
	</div>

	<div class="shade" style="display: none;">
		<div style="border: 0 solid #A75A5A;width:320px;border-radius:5px;left: 50%;top:35%;background-color: #fff;margin: -156px auto 0px -160px;position:fixed;">
	<div style="width:100%;padding-top:10px" align="right">
		<i class="weui-icon-cancel shade_div" style="font-weight:bold;color:#333;background-color:#fff;margin-right:10px"></i>
	</div>
			<div id="bcTarget" class="barcodeImg" style="text-align:center;"></div>
			<div id="invoiceName" style="text-align: center;width: 100%;margin: 30px auto 0 auto;white-space:normal;"></div>
			<div style="text-align: left;padding-left:30px;width:260px;margin: 10px 0 auto;white-space:normal;">
				<p>名称：<i id="ymc"></i></p>
				<p>税号：<i id="ysh"></i></p>
				<p>地址：<i id="ydz"></i></p>
				<p>电话：<i id="ydh"></i></p>
				<p>银行账号：<i id="yyh"></i></p>
				<!-- <p>帐号：<i id="yzh"></i></p> -->
			</div><br/>
		</div>
	</div>

<div style="display: none" class="page__ft">
<p><a style="color:#777;font-size:12px">四川航天金穗高技术有限公司</a> <b id="bbb"></b></p>
</div>
<script>
	var openid = $api.getStorage('openid');
	//api.alert({msg:"1"});



	function show() {
	    document.getElementById("dialog").style.display = "block";
	    window.setTimeout(function(){
	    	document.getElementById("dialog").style.display = "none";
	    }, 3000);
	}
	function addInfo(){
		//window.location.href='./Invoice_add.jsp?openid='+openid;
		api.openWin({
	        name: '增加机构',
	        url: './Invoice_add.html',
	        pageParam:{
	        	openid : openid
	        }
        });
	}

	function ddInfo(){
		//window.location.href='./Invoice_ddcx.jsp?openid='+openid;
		api.openWin({
	        name: '发票查询',
	        url: './Invoice_ddcx.html',
	        pageParam:{
	        	openid : openid
	        }
        });
	}

	function kpInfo(){
		//window.location.href='./Invoice_kpxx.jsp?openid='+openid;
		api.openWin({
	        name: '开票信息',
	        url: './Invoice_kpxx.html',
	        pageParam:{
	        	openid : openid
	        }
        });
	}

	function showDetail(id){
		//window.location.href='./Invoice_edit.jsp?id='+id+'&openid='+openid;
		api.openWin({
	        name: '发票编辑',
	        url: './Invoice_edit.html',
	        pageParam:{
	        	id : id,
	        	openid : openid
	        }
        });
	}

	var xlist;
	function gridUserInfo(){

		$("#loadingToast").fadeIn(100);
		apiready = function(){

			var header = $api.byId('jsheader');
			if(api.systemType=='ios'){
				$api.fixIos7Bar(header);
			}
//			else{
//				$api.fixStatusBar(header);
//			}


			api.addEventListener({
    				name: 'del_reload'
				}, function(ret, err) {
   				 	window.location.reload();
				});
			api.addEventListener({
    				name: 'edit_reload'
				}, function(ret, err) {
   				 	window.location.reload();
				});
			api.addEventListener({
    				name: 'reload'
				}, function(ret, err) {
   				 	window.location.reload();
				});
			api.ajax({
    			url: 'http://wechat.scjinsui.com/weixin/wxUser/gridUserInfo.do',
    			method: 'post',
    			data: {
     			   values: {
     			       openId: openid
     			   }
    			}
			}, function(ret, err) {
    			if (ret) {
    			    xlist=ret.xlist;
    			    //api.alert({msg:xlist[0].USERNAME});
    			    //console.log(xlist[0].USERNAME)；
	        	if(ret.flag != null){
	        		var len = xlist.length - 1;
	        		if(xlist[len].USERNAME !="" && typeof(xlist[len].USERNAME) != 'undefined'){
			        	var taxcode=xlist[len].TAXCODE==undefined?"&nbsp;":xlist[len].TAXCODE;
		        		var disc="该信息不支持开具增值税专用发票";
						if(xlist[len].TAXCODE!==undefined &&
								xlist[len].ADDRESS!==undefined &&
								xlist[len].BANK_NAME!==undefined &&
								xlist[len].BANK_NUMBER!==undefined &&
								xlist[len].PHONE_NUMBER!==undefined){
							disc="该信息支持开具增值税专用发票";
						}
						var s="<div class=\"FP_box clearfix\"><div class=\"fl\" style=\"width: 85%;\">"+
		        		"<div align='left' style='padding-left:30px;overflow: hidden;'><img style='width:150px;height:150px;position:absolute;' src='../../resource/bank/aisino.png'></img></div>"+
		    					"<h6><a style=\"color:#FFF; \">"+ xlist[len].USERNAME	+"</a></h6>"+
		    					"<p>&nbsp;</p><p style=\"padding-bottom: 45px;color:#fff;\" id=\"test\">"+taxcode+"</p></div>"+
		    					"<div class=\"fr\" style=\"margin-top:15px;\"><a href=\"javascript:;\" onclick=\"createQrcode('" + len + "')\"><img src=\"../../resource/EWM.png\" qrcode=\"\" invoicename=\"\" width=\"30\"></a>"+
		    			"</div><div class=\"FP_box_hint\">&nbsp;"+disc+"</div></div>";
						$("#FP_boxs").append(s);
	        		}
	        	}

	        	for(var i=0;i<xlist.length-1;i++){
	        		var taxcode=xlist[i].TAXCODE==undefined?"&nbsp;":xlist[i].TAXCODE;
	        		var disc="该信息不支持开具增值税专用发票";
					if(xlist[i].TAXCODE!==undefined &&
							xlist[i].ADDRESS!==undefined &&
							xlist[i].BANK_NAME!==undefined &&
							xlist[i].BANK_NUMBER!==undefined &&
							xlist[i].PHONE_NUMBER!==undefined){
						disc="该信息支持开具增值税专用发票";
					}
					var s="<div class=\"FP_box clearfix\"><div onclick='showDetail(\""+xlist[i].ID+"\")' class=\"fl\" style=\"width: 85%;\">"+
	        		"<div align='left' style='padding-left:30px;overflow: hidden;'></div>"+
	    					"<h6><a style=\"color:#fff \">"+ xlist[i].USERNAME	+"</a></h6>"+
	    					"<p>&nbsp;</p><p style=\"padding-bottom: 45px;color:#fff;\" id=\"test\">"+taxcode+"</p></div>"+
	    					"<div class=\"fr\" style=\"margin-top:15px;\"><a href=\"javascript:;\" onclick=\"createQrcode('" + i + "')\"><img src=\"../../resource/EWM.png\" qrcode=\"\" invoicename=\"\" width=\"30\"></a>"+
	    			"</div><div class=\"FP_box_hint\">&nbsp;"+disc+"</div></div>";
					$("#FP_boxs").append(s);
	        	}
   			 } else {
				api.alert({msg:'网络异常'});
   			 }
			});
		}

		setTimeout(function () {
			$("#loadingToast").fadeOut(100);
        }, 500);
	}
	    var mytime = null;
		function createQrcode(t){
			$("#invoiceName").empty();
			$(".shade").show();
			 //$("#bcTarget").empty().barcode(xlist[t].BANK_NUMBER, "code128B",{barWidth:2, barHeight:30,showHRI:false});
			//$("#bcTarget").empty().barcode(xlist[t].YW, "code93",{barWidth:2, barHeight:60,showHRI:false});
			$("#ymc").html("");
			$("#ysh").html("");
			$("#ydz").html("");
			$("#ydh").html("");
			$("#yyh").html("");
			$("#yzh").html("");
			$("#ymc").html(xlist[t].USERNAME);
			$("#ysh").html(xlist[t].TAXCODE);
			$("#ydz").html(xlist[t].ADDRESS);
			$("#ydh").html(xlist[t].PHONE_NUMBER);
			var yhzh = "";
			if(xlist[t].BANK_NAME!==undefined )
				yhzh += xlist[t].BANK_NAME;
			if(xlist[t].BANK_NUMBER!==undefined )
				yhzh += xlist[t].BANK_NUMBER;
			$("#yyh").html(yhzh);
			//$("#yzh").html(xlist[t].BANK_NUMBER);
			var orderid ="";
			$("#loadingToast").show();
			//api.alert({msg:openid+'---'+xlist[t].QR+'---'+xlist[t].YW});
			 api.ajax({
    			//url: 'http://192.168.76.50:8181/fpkj/orderid.do',
    			url: 'http://wechat.scjinsui.com/weixin/fpkj/orderid.do',
    			method: 'post',
    			data: {
      			  values: {
       			     openid:openid,
				     qr : xlist[t].QR,
				     yw : xlist[t].YW
       			 }
    			}
			}, function(ret, err) {
   			 if (ret) {
    			    if(ret.msg != "OK"){
				    		$("#loadingToast").hide();
				    		alert("数据加载失败...");
				    		$(".shade").hide();
				    		return;
				    	}
				    		orderid = ret.orderid;
				    		$("#loadingToast").hide();
				    		$("#bcTarget").empty().barcode(orderid, "code93",{barWidth:2, barHeight:60,showHRI:false});
				    		var info = "openid=" + openid + "&orderid=" + orderid + "&qr=" + xlist[t].QR;
							var qrcode = new QRCode("invoiceName", {
							   // text: xlist[t].QR,
							    text : info,
							    width: 150,
							    height: 150,
							    colorDark : "#000000",
							    colorLight : "#ffffff",
							    correctLevel : QRCode.CorrectLevel.H
							});
    			} else {
    			    $("#loadingToast").hide();
				    //alert("服务请求错误:" + xhr.status);
				    //api.alert({msg:'服务请求错误:'+JSON.stringify(err)});
				    api.alert({msg:'网络异常'});
    			}
			});


		}

		$(".shade_div").click(function() {
// 			if(confirm('关闭二维码就不能在线支付或发票开具，你确定关闭吗？')){
				$(".shade").hide();
//				if(mytime != null){
//					clearTimeout(mytime);
//				}
// 			}

		});


		function qrcode(qrcode){
			$(".shade").show();
		};





		function gainOrder(){
//			jQuery.ajax({
//			    url:"<%=basePath %>fpkj/gainOrderNum.do",
//			    type:"post",
//			    data:{},
//			    dataType: "json",
//			    error:function(xhr, textStatus, errorThrown){
//			         console.log("服务请求错误,请联系管理员【错误代码："+xhr.status+"】");
//			    },
//			    success: function (data) {
//
//
//			    }
//			});
			api.ajax({
    			url: 'http://wechat.scjinsui.com/weixin/fpkj/gainOrderNum.do',
    			method: 'post',
    			data: {

    			}
			}, function(ret, err) {
    			if (ret) {
     			   api.alert({ msg: JSON.stringify(ret) });
   			 } else {
    			    //api.alert({ msg: JSON.stringify(err) });
    			    api.alert({msg:'网络异常'});
   			 }
			});
		}
	/**
		function test(){
			var qr = "Id=&adId=&codeType=004&currencyCode=&invoiceMerId=Vy3hhfVf66oZNcqUkVItjQh7uBIs5LXnk31Cqa3roBg=&invoiceUserId=&payeeId=&payerId=&signature=&terminalId=ThuEnamSpZgmopZacW8UEA==&txnAmt=&version=1.0.0";
			//var qr = "Id=&adId=&codeType=004&currencyCode=&invoiceMerId=cPadfhBrDK7Bv94go7fFTTNS/fDgMUJnYp++gSlTA2A=&invoiceUserId=&payeeId=&payerId=&signature=&terminalId=/NQ8de78gGn3lKryxFa20g==&txnAmt=&version=1.0.0";
			var strs= qr.split("&");
			var parms = "";
		 	for(var i=0;i<strs.length;i++){
		 		if(strs[i].indexOf("invoiceMerId") == 0){
		 			parms += "&" +  strs[i];
		 		}
		 		if(strs[i].indexOf("terminalId") == 0){
		 			parms += "&" + strs[i];
		 		}
		 	}
		 	//alert(parms);
		 	window.location.href = "fpkj/merid.do?kpid=lNxVzfPaElMXs73UgCQmAnpF9jP/LGfqi0cT/ME8uU0=" + "&openid=oOQHZv2o_LmZPnCGs-0jktHJzBpc" + parms;
		}
**/
var ua = navigator.userAgent.toLowerCase();
var isWeixin = ua.indexOf('micromessenger') != -1;
var isAndroid = ua.indexOf('android') != -1;
var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1);


if (!isWeixin) {
	//openid="123456";
	gridUserInfo();

}else{//微信客户端
	//config 注入成功后异步回调wx.ready方法
	jQuery.ajax({
		    url:"<%=basePath %>weixin/wx.do",
		    type:"post",
		    data:{
		    	code : '<%=code%>',
		    	state : '<%=state%>'
		    },
		    dataType: "json",
		    error:function(xhr, textStatus, errorThrown){
		         console.log("服务请求错误,请联系管理员【错误代码："+xhr.status+"】");
		    },
		    success: function (data) {
		    	if(data.msg =='OK'){
		    		//alert(data.appId);
		    		wx.config({
		    			debug : false,
		    			appId : data.appId,
		    			timestamp : data.timestamp,
		    			nonceStr : data.nonceStr,
		    			signature : data.signature,
		    			jsApiList : [ 'checkJsApi', 'onMenuShareTimeline',
		    					'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo',
		    					'onMenuShareQZone', 'hideMenuItems', 'showMenuItems',
		    					'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem',
		    					'translateVoice', 'startRecord', 'stopRecord',
		    					'onVoiceRecordEnd', 'playVoice', 'onVoicePlayEnd',
		    					'pauseVoice', 'stopVoice', 'uploadVoice', 'downloadVoice',
		    					'chooseImage', 'previewImage', 'uploadImage', 'downloadImage',
		    					'getNetworkType', 'openLocation', 'getLocation',
		    					'hideOptionMenu', 'showOptionMenu', 'closeWindow',
		    					'scanQRCode', 'chooseWXPay', 'openProductSpecificView',
		    					'addCard', 'chooseCard', 'openCard' ]
		    		});
		    		gridUserInfo();
		    	}else{
		    		//alert(data.msg);
		    		api.alert({msg:ret.msg});
		    	}

		    }
	});

}

$(function(){
	var $searchBar = $('#searchBar'),
    $searchResult = $('#searchResult'),
    $searchText = $('#searchText'),
    $searchInput = $('#searchInput'),
    $searchClear = $('#searchClear'),
    $searchCancel = $('#searchCancel');
	function hideSearchResult(){
    	$searchResult.hide();
    	$searchInput.val('');
	}
	function cancelSearch(){
    	hideSearchResult();
    	$searchBar.removeClass('weui-search-bar_focusing');
    	$searchText.show();
	}
	$searchText.on('click', function(){
    	$searchBar.addClass('weui-search-bar_focusing');
    	$searchInput.focus();
	});
	$searchInput.on('blur', function () {
        if(!this.value.length){
        	cancelSearch();
        }
    }).on('input', function(){
        if(this.value.length) {
        	$("#searchResult").html("");
        	selectList();
            $searchResult.show();
        } else {
            $searchResult.hide();
        }
    });
	$searchClear.on('click', function(){
    	hideSearchResult();
    	$searchInput.focus();
	});
	$searchCancel.on('click', function(){
    	cancelSearch();
    	$searchInput.blur();
	});
});

function selectList()
{
	$("#searchResult").html("");
	var keywords=$("#searchInput").val();
		//api.alert({msg:JSON.stringify(keywords)});
		for(var i=0;i<xlist.length;i++){
		//api.alert({msg:JSON.stringify(xlist[i].USERNAME)});
			//if(xlist[i].USERNAME+''.indexOf(keywords) != -1 && xlist[i].USERNAME!='undefined' && typeof(xlist[i].USERNAME)!='undefined'){
			if((xlist[i].USERNAME+'').indexOf(keywords)!=(-1) && xlist[i].USERNAME!='undefined' && typeof(xlist[i].USERNAME)!='undefined'){
	 		 	var s="<div  class=\"weui-cell weui-cell_access\">"+
	 		 		"<div class=\"weui-cell__bd weui-cell_primary\" onclick='showDetail(\""+xlist[i].ID+"\")'>"+
	 		 		"<p>"+ xlist[i].USERNAME +"</p>"+
	 		 		"</div></div>";
	 		 	$("#searchResult").append(s);
			}
		}
		if($("#searchResult").html()=="")
		{
			var s="<div  class=\"weui-cell weui-cell_access\">"+
		 		"<div class=\"weui-cell__bd weui-cell_primary\">"+
		 		"<p style=\"top:40px>没有查找到相关信息</p>"+
		 		"</div></div>";
		 	$("#searchResult").append(s);
		}
	}

	function scanQRCode(id){
		wx.scanQRCode({
		    desc: 'scanQRCode desc',
		    needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
		    scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
		    success: function (res) {
	    	//var tom = parseQuery(res.resultStr); // 当needResult 为 1 时，扫码返回的结果
		   	 var strs= res.resultStr.split("&");
			 var parms = "";
		 	for(var i=0;i<strs.length;i++){
		 		if(strs[i].indexOf("invoiceMerId") == 0){
		 			parms += "&" +  strs[i];
		 		}
		 		if(strs[i].indexOf("terminalId") == 0){
		 			parms += "&" + strs[i];
		 		}
		 	}
		 	if(parms == ""){
		 		//alert("没有扫描到相关信息！");
		 		api.alert({msg:'没有扫描到相关信息！'});
		 	}
		 	//window.location.href = '<%=basePath %>fpkj/merid.do?kpid='+ encodeURIComponent(id) + "&openid="+encodeURIComponent(openid) + parms;
			api.ajax({
    			url: 'http://wechat.scjinsui.com/weixin/fpkj/merid.do',
    			method: 'post',
    			data: {
     			   values: {
      			      kpid : encodeURIComponent(id),
      			      openid : encodeURIComponent(openid) + parms
     			   }
    			}
			}, function(ret, err) {
  			  if (ret) {
   			     //api.alert({ msg: JSON.stringify(ret) });
   			 } else {
    			    //api.alert({ msg: JSON.stringify(err) });
    			    api.alert({msg:'网络异常'});
    			}
			});
			}
		});
	}

	var parseQuery = function(query){
    var reg = /([^=&\s]+)[=\s]*([^&\s]*)/g;
    var obj = {};
    while(reg.exec(query)){
        obj[RegExp.$1] = RegExp.$2;
    }
    return obj;
	};


</script>
</body></html>
